﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using SourceCode.Workflow.Client;
using ASBCC.Database.Entity;

namespace ASBCC.Workflow.K2Manager
{
    public class K2User
    {
        private int _userId;
        public virtual int UserId { get { return _userId; } set { _userId = value; } }

        private string _userEn;
        public virtual string UserEn { get { return _userEn; } set { _userEn = value; } }

        private string _userCn;
        public virtual string UserCn { get { return _userCn; } set { _userCn = value; } }

        public K2User(int userId, string userEn, string userCn)
        {
            _userId = userId;
            _userEn = userEn;
            _userCn = userCn;
        }

        public K2User()
        {
        }

        public const int TempUser = -1000; 
    }

    public class K2AppForm
    {
        private int _formId;
        public int FormId { get { return _formId; } set { _formId = value; } }

        private string _folio;
        public string Folio { get { return _folio; } set { _folio = value; } }

        private K2User _applicant = new K2User();
        public K2User Applicant { get { return _applicant; } }

        private string _applicationNo;
        public string ApplicationNo { get { return _applicationNo; } set { _applicationNo = value; } }

        private K2User _creator = new K2User();
        public K2User Creator { get { return _creator; } }

        private K2User _currentUser = new K2User();
        public K2User CurrentUser { get { return _currentUser; } }

        private K2User _delegateFrom = new K2User();
        public K2User DelegateFrom { get { return _delegateFrom; } }

        //表单预期的状态(即执行完操作后的状态)
        private string _futureFormStatus;
        public string FutureFormStatus { get { return _futureFormStatus; } set { _futureFormStatus = value; } }

        private string _title;
        public string Title { get { return _title; } set { _title = value; } }

        private string _moduleName;
        public string ModuleName { get { return _moduleName; } set { _moduleName = value; } }

        public K2AppForm()
        {
        }

        public K2AppForm(int formId, string folio, string applicationNo,
            int applicantId, string applicantEn, string applicantCn,
            int creatorId, string creatorEn, string creatorCn,
            int currentUserId, string currentUserEn, string currentUserCn,
            int delegateFromId, string delegateFromEn, string delegateFromCn,
            string futureFormStatus, string title, string moduleName)
        {
            this._formId = formId;
            this._folio = folio;
            this._applicant.UserId = applicantId;
            this._applicant.UserEn = applicantEn;
            this._applicant.UserCn = applicantCn;
            this._applicationNo = applicationNo;
            this._creator.UserId = creatorId;
            this._creator.UserEn = creatorEn;
            this._creator.UserCn = creatorCn;
            this._currentUser.UserId = currentUserId;
            this._currentUser.UserEn = currentUserEn;
            this._currentUser.UserCn = currentUserCn;
            this._delegateFrom.UserId = delegateFromId;
            this._delegateFrom.UserEn = delegateFromEn;
            this._delegateFrom.UserCn = delegateFromCn;
            this._futureFormStatus = futureFormStatus;
            this._title = title;
            this._moduleName = moduleName;
        }
    }

    public class K2WorkItem
    {
        private Guid _myActivityId;
        public Guid MyActivityId { get { return _myActivityId; } set { _myActivityId = value; } }

        private Guid _actionRecordId;
        public Guid ActionRecordId { get { return _actionRecordId; } set { _actionRecordId = value; } }

        private DateTime _arrvialDate;
        public DateTime ArrvialDate { get { return _arrvialDate; } set { _arrvialDate = value; } }

        private string _procName;
        public string ProcName { get { return _procName; } set { _procName = value; } }

        private string _activityName;
        public string ActivityName { get { return _activityName; } set { _activityName = value; } }

        private int _procInstId;
        public int ProcInstId { get { return _procInstId; } set { _procInstId = value; } }

        private int _actInstDestId;
        public int ActInstDestId { get { return _actInstDestId; } set { _actInstDestId = value; } }

        private string _destination;
        public string Destination { get { return _destination; } set { _destination = value; } }

        public K2WorkItem()
        {
        }

        public K2WorkItem(DateTime arrvialDate, string procName, string activityName, int procInstID, int actInstDestID, string destination, Guid myActivityId, Guid actionRecordId)
        {
            this._arrvialDate = arrvialDate;
            this._procName = procName;
            this._activityName = activityName;
            this._procInstId = procInstID;
            this._actInstDestId = actInstDestID;
            this._destination = destination;
            this._myActivityId = myActivityId;
            this._actionRecordId = actionRecordId;
        }
    }

    public class K2ActionInfo
    {
        private string _actionType;
        public string ActionType { get { return _actionType; } set { _actionType = value; } }

        private string _actionName;
        public string ActionName { get { return _actionName; } set { _actionName = value; } }

        private string _auditRule;
        public string AuditRule { get { return _auditRule; } set { _auditRule = value; } }

        public K2ActionInfo()
        {
        }

        public K2ActionInfo(string actionType, string actionName, string auditRule)
        {
            this._actionType = actionType;
            this._actionName = actionName;
            this._auditRule = auditRule;
        }
    }

    public class K2ActionType
    {
        public const string Submit = "Submit";
        public const string Resubmit = "Resubmit";
        public const string Approve = "Approve";
        public const string Reject = "Reject";
        public const string Review = "Review";
        public const string Forward = "Forward";
        public const string ForwardBack = "ForwardBack";
        public const string ReplyForwardBack = "ReplyForwardBack";
        public const string AskForMore = "AskForMore";
        public const string ReplyAskForMore = "ReplyAskForMore";
        public const string Discard = "Discard";
        public const string Drawback = "Drawback";
        public const string Withdraw = "Withdraw";
        public const string Cancel = "Cancel";
        public const string Redirect = "Redirect";
        public const string Goto = "Goto";
        public const string Acknowledge = "Acknowledge";
        public const string PostSave = "PostSave";
        public const string PostSubmit = "PostSubmit";
        public const string Validate = "Validate";
        public const string Upload = "Upload";

        public const string Close = "Close";
        public const string Save = "Save";
        public const string Edit = "Edit";
        public const string Log = "Log";
        public const string Comment = "Comment";
        public const string Print = "Print";
        public const string Back = "Back";
    }

    public class K2ActionName
    {
        public const string Submit = "Submit";
        public const string Back = "Back";
        public const string Cancel = "Cancel";
        public const string GotoSelf = "GotoSelf";
        public const string Update = "Update";
    }

    public class K2StampType
    {
        public const string Done = "Done";
        public const string Active = "Active";
        public const string Tobe = "Tobo";
    }

    public class K2ActivityName
    {
        public const string Start = "Start";
        public const string Submission = "Submission";
        public const string End = "End";
    }

    public enum K2ActionRecordStatus
    {
        Normal,
        NoNeedBackTracking,
        BackTracked
    }
    public enum ApproveMode
    {
        All,
        Anyone 
    }
    public enum MyActivityStatus
    {
        Normal,
        Suspended,
        Disabled
    }

    public enum ProcessInstanceStatus
    {
        Error = 0,
        Running = 1,
        Active = 2,
        Completed = 3,
        Stopped = 4,
        Deleted = 5,
        Undefined = 0x63,
        NotInK2Server = 6
    }

    public enum MailRule
    {
        Never = 1,
        PerActivity = 2,
        PerHalfDay = 3,
        PerDey = 4
    }

    public static class K2Consts
    {
        public const string Platform = "ASP";

        //public const string DataField_Key_FormURL = "FormURL";
        public const string DataField_Key_FormURL = "FromURL";
        public const string XmlField_Key_AuditDestination = "AuditDestination";

        public const string XmlField_Key_AuditDestinationFormat = "AuditDestination{0}"; //预留，如果有超过个1个节点需要Destination，则Key的名称依次为AuditDestination1、AuditDestination2..
    }
}
